﻿<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets" template="/template/main.xhtml">
	<ui:define name="body">
		<h:form prependId="false">
			<p:fieldset legend="#{messages['cliente.label']}" toggleable="false" toggleSpeed="500">
				<h:panelGrid id="fields" columns="3">
					<h:outputLabel value="#{messages['cliente.label.empresa']}: " for="empresa" styleClass="text-input" />
					<p:selectOneMenu id="empresa" value="#{clienteEditMB.bean.empresa}" tabindex="1"
						style="width: 23em">
						<f:selectItems value="#{clienteEditMB.empresas}" var="emp" itemLabel="#{emp.nome}"/>
					</p:selectOneMenu>
					<p:message for="empresa" />
					<h:outputLabel value="#{messages['cliente.label.nome']}: " for="nome" styleClass="text-input" />
					<p:inputText id="nome" value="#{clienteEditMB.bean.nome}"  tabindex="2"
						styleClass="longInput" title="#{messages['cliente.alt.nome']}" />
					<p:message for="nome" />
					<h:outputLabel value="#{messages['cliente.label.documento']}: " for="documento" styleClass="text-input" />
					<p:inputMask id="documento" value="#{clienteEditMB.bean.documento}" mask="999.999.999-99" tabindex="3"
						styleClass="mediumInput" title="#{messages['cliente.alt.documento']}" />
					<p:message for="documento" />
					<h:outputLabel value="#{messages['cliente.label.codigo']}: " for="codigo" styleClass="text-input" />
					<p:inputText id="codigo" value="#{clienteEditMB.bean.codigo}" tabindex="4"
						styleClass="shortInput" title="#{messages['cliente.alt.codigo']}" />
					<p:message for="codigo" />
					<h:outputLabel value="#{messages['cliente.label.telefone']}: " for="telefone" styleClass="text-input" />
					<p:inputMask id="telefone" value="#{clienteEditMB.bean.telefone}" mask="(99) 9999-9999" tabindex="5"
						styleClass="mediumInput" title="#{messages['cliente.alt.telefone']}" />
					<p:message for="telefone" />
				</h:panelGrid>
			</p:fieldset>
			<p:toolbar>
				<p:toolbarGroup align="left">
					<p:commandButton value="#{messages['button.save']}" action="#{clienteEditMB.insert}"
						rendered="#{!clienteEditMB.updateMode}" ajax="false" />
					<p:commandButton value="#{messages['button.save']}" action="#{clienteEditMB.update}"
						rendered="#{clienteEditMB.updateMode}" ajax="false" />
					<p:commandButton value="#{messages['button.delete']}" onclick="confirmation.show()"
						rendered="#{clienteEditMB.updateMode}" type="button" immediate="true" ajax="false" />
					<p:confirmDialog message="#{messages['label.confirm.delete']}" showEffect="bounce" hideEffect="explode"
						header="#{messages['label.dialog.delete']}" severity="alert" widgetVar="confirmation">
						<h:commandButton value="#{messages['button.dialog.yes']}" action="#{clienteEditMB.delete}" immediate="true"
							ajax="false" />
						<h:commandButton value="#{messages['button.dialog.no']}" onclick="confirmation.hide()" type="button" />
					</p:confirmDialog>
				</p:toolbarGroup>
				<p:toolbarGroup align="right">
					<p:commandButton value="#{messages['button.changepass']}" onclick="dlg.show()"
						rendered="#{cantinaEditMB.updateMode}" type="button" immediate="true" ajax="false" />
					<p:dialog id="dialog" modal="true" header="#{messages['label.confirm.changepass']}" 
						widgetVar="dlg">
						<h:messages id="msgSenhas"/>
						<h:panelGrid columns="2">
							
							<h:outputLabel value="Digite a Nova Senha:*" for="senha" />
							<p:password id="senha" value="#{clienteEditMB.novaSenha}" match="repita" validatorMessage="Senhas devem ser idênticas!!!"/>

							<h:outputLabel value="Repita a Nova Senha:*" for="repita" />
							<p:password id="repita" value="#{clienteEditMB.novaSenha}"/>
							
							<f:facet name="footer">
								<p:commandButton id="mudarSenha" value="Confirmar" update="msgSenhas" 
									actionListener="#{clienteEditMB.alterarSenha}"
									oncomplete="handleLoginRequest(xhr, status, args)"/>
							</f:facet>
						</h:panelGrid>
					</p:dialog>
				</p:toolbarGroup>
			</p:toolbar>
		</h:form>
		<script type="text/javascript">  
		    function handleLoginRequest(xhr, status, args) {  
		        if(args.validationFailed || !args.serverValidation) {  
		            dlg.jq.effect("shake", { times:5 }, 100);  
		        }   
		        else {  
		            dlg.hide();  
		        }  
		    }  
		</script>
	</ui:define>
</ui:composition>